home *** CD-ROM | disk | FTP | other *** search
- Path: info.uah.edu!oreo!gbacon
- From: gbacon@oreo (Greg Bacon)
- Newsgroups: comp.lang.c
- Subject: Re: hex to dec function?
- Date: 14 Mar 1996 04:38:46 GMT
- Organization: The University of Alabama in Huntsville
- Message-ID: <4i87sm$7n0@info.uah.edu>
- References: <4gdh1b$bg@mailhost.mwmicro.com> <4hl8mk$1er@info.uah.edu> <313EE885.4511@cmt.lpr.mail.carel.fi>
- Reply-To: gbacon@CS.UAH.Edu
- NNTP-Posting-Host: oreo.aspire.cs.uah.edu
- X-Newsreader: TIN [version 1.2 PL2]
-
- Ari Lukumies (aril@cmt.lpr.mail.carel.fi) wrote:
- : Greg Bacon wrote:
- : >
-
- : [snip]
-
- : > Assuming you have a string representing some hexadecimal quantity and
- : > you want to print its equivalent decimal value:
- : >
- : > #include <stdio.h>
- : > #include <stdlib.h>
- : >
- : > /*
- : > :
- : > :
- : > */
- : > {
- : > char *strHexVal = "20"; /* 32 auf decimal */
- : >
- : > (void) printf("%d\n", strtol(strHexVal, (char **) NULL, 10));
- : > [snip]
-
- : Just a quick sidenote: if you use strtol() in a printf call, use the
- : correct format string, also: "%ld\n".
-
- : Later,
- : AriL
-
- OK, OK.. you got me. I should have commented that I was assuming int
- and long were of the same length (a trait not often found on the
- braindead iAPX platform :).
-
- The above works on most modern Unices.
-
- Greg
- --
- Greg Bacon <gbacon@cs.uah.edu>
- University of Alabama in Huntsville
- CS Department Systems Support Team
-